<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition template="/templates/templateListar.xhtml"
	xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:p="http://primefaces.org/ui"
	xmlns:fn="http://java.sun.com/jsp/jstl/functions">

	<ui:define name="conteudo">

		<ui:param name="actionBean" value="#{sessionScope[clienteMB]}" />

		<h:form id="frmCliente">

			<p:hotkey bind="esc"
				handler="document.getElementById('frmTab:btnCancelar').click()" />

		</h:form>
		<h:form id="frmTab">
			<p:commandButton id="btnCancelar" action="#{clienteMB.sair}"
				style="display:none" immediate="true" value="sair"></p:commandButton>
			<p:commandButton action="#{clienteMB.prepararIncluir}"
				value="Novo Registro" icon="ui-icon-disk" style="float:left">
			</p:commandButton>
			<p:dataTable id="tabela" var="item" value="#{clienteMB.lista}" rowStyleClass="ui-datatable-even"
				paginatorPosition="bottom" paginator="true" rows="10"
				emptyMessage="Não há registros na lista" rowKey="#{item.codigo}"
				paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
				currentPageReportTemplate="(Página: {currentPage}/{totalPages})"
				rowsPerPageTemplate="10,15,25,50,100" selectionMode="single">
				<f:facet name="header">Cadastro de Clientes
				</f:facet>
				<p:column headerText="Codigo" style="width: 10%;"
					sortBy="#{item.codigo}">
					<h:outputText value="#{item.codigo}" />
				</p:column>
				<p:column headerText="Nome" sortBy="#{item.dadosCadastro.nome}"
					filterBy="#{item.dadosCadastro.nome}" filterMatchMode="contains">
					<h:outputText value="#{item.dadosCadastro.nome}" />
				</p:column>

				<p:column headerText="CNPJ/CPF"
					sortBy="#{item.dadosCadastro.cnpjCpf}"
					filterBy="#{item.dadosCadastro.cnpjCpf}" filterMatchMode="contains">
					<p:outputLabel value="#{item.dadosCadastro.cnpjCpf}"></p:outputLabel>
				</p:column>

				<p:column headerText="E-mail" sortBy="#{item.dadosCadastro.email}"
					filterBy="#{item.dadosCadastro.email}" filterMatchMode="contains">
					<h:outputText value="#{item.dadosCadastro.email}" />
				</p:column>

				<p:column headerText="Ação" style="text-align:center">


					<p:commandButton action="#{clienteMB.prepararAlterar}"
						styleClass="styleBotao" icon="ui-icon-pencil" title="Alterar">
						<f:setPropertyActionListener value="#{item.clone()}"
							target="#{clienteMB.cliente}" />
					</p:commandButton>

					<p:commandButton action="#{clienteMB.prepararConsultar}"
						styleClass="styleBotao" icon="ui-icon-search" title="Consultar">

						<f:setPropertyActionListener value="#{item.clone()}"
							target="#{clienteMB.cliente}" />
					</p:commandButton>

					<p:commandButton actionListener="#{clienteMB.excluir}" title="Excluir"
						icon="ui-icon-close" styleClass="styleRed" update=":Excluir"
						oncomplete="confirmation.show()">
						<f:setPropertyActionListener value="#{item.clone()}"
							target="#{clienteMB.cliente}" />
					</p:commandButton>

				</p:column>

				<f:facet name="footer">
					<p:outputLabel value="Total de " />
					<p:outputLabel value="#{fn:length(clienteMB.lista)} registro(s)" />

				</f:facet>

			</p:dataTable>
		</h:form>

		<ui:include src="/includes/confirmacaoExcluir.xhtml" />
	</ui:define>
</ui:composition>
